<template>
  <div class="CL-box1" style="width:100%">
    <section class="CL-min">
      <div class="CL-box2">
        <!-- 上框 -->
        <div class="CL-top" >
          <div class="CL-search">
            <div class="CL-smsesrch">
              <div class="CL-text1">策略搜索 :</div>
              <div class="CL-int">
                <el-input v-model="searchinfo.policyName" placeholder="请输入"></el-input>
              </div>
              <div class="CL-text2">
                <el-button type="primary" class="el-icon-search" @click="searchbtn"
                  >查询</el-button
                >
              </div>
            </div>
          </div>
        </div>
        <div class="CL-cenbox">
          <div class="CL-top1">
            <!-- 新建按钮 -->
            <el-button type="text" @click="dialogVisible = true">
              <i class="el-icon-circle-plus-outline"></i>
              <span class="CL-txtcor">新建</span>
            </el-button>
            <!--弹窗 表头 -->
            <el-dialog :title="type" :visible="dialogVisible" width="30%" @close="dialogVisible=false">
              <!--弹窗 表单1 -->
              <el-form  :model="create" ref="create" label-width="100px" class="demo-dynamic">
                <el-form-item prop="policyName" label="策略名称" :rules="{required: true,message:'重新输入'}">
                  <el-input placeholder="请输入" v-model="create.policyName" maxlength="10" clearValidate></el-input>
               </el-form-item>
                 <!-- 表单1结束 -->
               <!-- 表单2 -->
               <el-form-item prop="discount" label="策略名称" :rules="{required: true,message:'重新输入'}" >
                  <el-input placeholder="请输入" v-model="create.discount"></el-input>
               </el-form-item>``
              <!-- 表单2结束 -->
              </el-form>
              <!-- 底部按钮 -->
              <span slot="footer" class="dialog-footer" style="text-align: center;">
                <div class="CL-foot">
                  <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="createcl">确 定</el-button>
                </div>
              </span>
              <!-- 按钮结束 -->
            </el-dialog>
            <!--弹窗表格结束 -->
          </div>
          <!-- 表单 -->
          <div class="CL-from" style="width:100%">
            <template>
              <el-table :data="CLlist" class="CL-biaodan" style="width:100%">
                <el-table-column prop="policyId" label="序号" width="80px" height="23px" font-size= "14px">
                </el-table-column>
                <el-table-column prop="policyName" label="策略名称" min-width="200px" height="42px" >
                </el-table-column>
                <el-table-column prop="discount" label="策略方案" min-width="200px" height="23px">
                </el-table-column>
                <el-table-column prop="createTime" label="创建日期" width="170px" height="23px">
                </el-table-column>
                <el-table-column prop="tableData" label="操作" min-width="140px" height="23px">
                  <!-- 三个弹框盒子 -->
                  <!-- 1.1 -->
                 <template v-slot=" { row }">
                   <el-button type="text" @click="centerDialogVisible = true">查看详情</el-button>
                  <el-button type="text" @click="edit(row)" >修改</el-button>
                  <!-- 删除 -->
                  <el-button style="color:red"
                  @click="delcomList( row.policyId)">
                  删除</el-button>
                 </template>
                  <!-- 1.1结束 -->
                </el-table-column>
              </el-table>
            </template>
          </div>
        </div>
      </div>
    </section>
    <el-dialog title="修改" :visible.sync="centerDialogVisible" width="30%" center>

    </el-dialog>
    </div>
</template>

<script>
import { tackcommodity, delcomList, searchbtn, addcl, editcl } from '@/api/strategy'
export default {
  // 获取列表
  async created () {
    const { data } = await tackcommodity()
    this.CLlist = data
    // console.log(data);
    // console.log(this.CLlist);
  },
  data () {
    return {
      searchinfo: {
        policyName: '',
        pageIndex: 1,
        pageSize: 10
      },
      create: {
        discount: '',
        policyName: '',
        policyId: ''
      },
      centerDialogVisible: false,
      dialogVisible: false,

      text: '',
      textarea: '',
      CLlist: [], // 接收列表数据
      num: 0,
      type: '新增策略'

      // dynamicValidateForm: {
      //   domains: [{
      //     value: ''
      //   }],
      //   PName: '',
      //   PPlane: '',
      // }
    }
  },
  methods: {
    edit (row) {
      console.log(row)
      this.type = '修改策略'
      this.create.discount = row.discount
      this.create.policyName = row.policyName
      this.create.policyId = row.policyId
      this.dialogVisible = true
    },
    async createcl () {
      if (this.type === '新增策略') {
        const res = await addcl(this.create)
        console.log(res)
      } else {
        await editcl(this.create)
      }
      this.dialogVisible = false
      this.searchbtn()
    },
    async searchbtn () {
      const { data } = await searchbtn(this.searchinfo)
      console.log(data)
      this.CLlist = data.currentPageRecords
      this.searchinfo.pageIndex = data.pageIndex
    },

    // 删除
    async delcomList (id) {
      console.log(id)
      try {
        await this.$confirm('确定删除')
        // 只有点击确定才可以进行下一步
        await delcomList(id)
        this.tackcommodity()
        this.$message.success('删除成功')
      } catch (error) {
        console.log(error)
      } finally {
        this.searchbtn()
      }
    }

  }
}
</script>

<style lang="less" scoped>
.CL-box1 {
  width: 100%;
  height: 800px;
  // background-color: pink;
  .CL-min {
    margin-top: 60px;
    padding: 20px;
  }
  .CL-box2 {
      width: 100%;

    height: 700px;
    // background-color: burlywood;
  }
  .CL-top {
    width:100%;
    height: 64px;
    display: flex;
    // background-color: aquamarine;
    margin-bottom: 20px;
    padding-left: 17px;
  }
  .CL-search {
    width: 387.4px;
    height: 36px;
    // background-color: rgb(114, 95, 160);
    .CL-smsesrch {
      display: flex;
      justify-content: space-between;
      width: 401.4px;
      height: 36px;
      margin-top: 12px;
      // background-color:blanchedalmond;
    }
    .CL-text1 {
      width: 85px;
      height: 36px;
      font-size: 14px;
      color: #606266;
      padding: 0 12px 0 0;
      margin-top: 9px;
      text-align: right;
    }
    .CL-int {
      width: 205px;
      height: 35px;
      margin-right: 50px;
      // background-color: yellowgreen;
    }
    .CL-text2 {
      width: 80px;
      height: 36px;
      margin-right: 10px;
      // background-color: #5f84ff;
    }
    .el-button--primary {
      margin-right: 10px;
    }
  }
  //弹窗样式
  .CL-cenbox {
    width:100%;
    height: 359px;
    // background-color: turquoise;
    .CL-top1 {
          width:100%;

      height: 36px;
      // color: #fff;
      // background-color: aqua;
      .el-button--text {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        justify-content: center;
        -webkit-box-align: center;
        -ms-flex-align: center;
        align-items: center;
        width: 80px !important;
        height: 36px;
        padding: 0;
        background: linear-gradient(135deg, #ff9743, #ff5e20) !important;
        border: none;
        .el-icon-circle-plus-outline {
          width: 16px;
          height: 16px;
          color: #fff;
        }
        .CL-txtcor {
          font-size: 14px;
          color: #fff;
        }
      }
    }
    .CL-from {
          width:100%;

      height: 262px;
      // background-color: slategrey;
    .CL-foot{
      text-align: center;
    }
    }
  }
  .CLinp{
    display: flex;
    width: 410px;
    height: 40px;
    margin-left: 50px;
    // background-color: aqua;
    .CLkk{
      width: 450px;
    height: 47px;

    }
    .CLbt{
      width: 50px;
      height: 40px;
      margin-top: -10px;
      display: flex;
      flex-wrap: wrap;
    }
    .top1{
      width: 50px;
      height: 20px;
    }
    .top2{
      width: 50px;
      height: 20px;
    }
   .el-icon-arrow-up{
      margin-left: 19px;
   }
   .el-icon-arrow-down{
    margin-left: 19px;
   }
  }
}
</style>
